<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>aria_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_a11y_aria_aria_test.js.html">aria_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2008 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.goog.provide(&#39;goog.a11y.ariaTest&#39;);
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.a11y.ariaTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.a11y.ariaTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.a11y.aria&#39;);
<a name="line19"></a>goog.require(&#39;goog.a11y.aria.Role&#39;);
<a name="line20"></a>goog.require(&#39;goog.a11y.aria.State&#39;);
<a name="line21"></a>goog.require(&#39;goog.dom&#39;);
<a name="line22"></a>goog.require(&#39;goog.dom.TagName&#39;);
<a name="line23"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line24"></a>
<a name="line25"></a>var ARIA = goog.a11y.aria;
<a name="line26"></a>var Role = goog.a11y.aria.Role;
<a name="line27"></a>var State = goog.a11y.aria.State;
<a name="line28"></a>var sandbox;
<a name="line29"></a>var someDiv;
<a name="line30"></a>var someSpan;
<a name="line31"></a>var htmlButton;
<a name="line32"></a>
<a name="line33"></a>function setUp() {
<a name="line34"></a>  sandbox = goog.dom.getElement(&#39;sandbox&#39;);
<a name="line35"></a>  someDiv = goog.dom.createDom(
<a name="line36"></a>      goog.dom.TagName.DIV, {id: &#39;someDiv&#39;}, &#39;DIV&#39;);
<a name="line37"></a>  someSpan = goog.dom.createDom(
<a name="line38"></a>      goog.dom.TagName.SPAN, {id: &#39;someSpan&#39;}, &#39;SPAN&#39;);
<a name="line39"></a>  htmlButton = goog.dom.createDom(
<a name="line40"></a>      goog.dom.TagName.BUTTON, {id: &#39;someButton&#39;}, &#39;BUTTON&#39;);
<a name="line41"></a>  goog.dom.appendChild(sandbox, someDiv);
<a name="line42"></a>  goog.dom.appendChild(someDiv, someSpan);
<a name="line43"></a>}
<a name="line44"></a>
<a name="line45"></a>function tearDown() {
<a name="line46"></a>  goog.dom.removeChildren(sandbox);
<a name="line47"></a>  someDiv = null;
<a name="line48"></a>  someSpan = null;
<a name="line49"></a>  htmlButton = null;
<a name="line50"></a>}
<a name="line51"></a>
<a name="line52"></a>function testGetSetRole() {
<a name="line53"></a>  assertNull(&#39;someDiv\&#39;s role should be null&#39;, ARIA.getRole(someDiv));
<a name="line54"></a>  assertNull(&#39;someSpan\&#39;s role should be null&#39;, ARIA.getRole(someSpan));
<a name="line55"></a>
<a name="line56"></a>  ARIA.setRole(someDiv, Role.MENU);
<a name="line57"></a>  ARIA.setRole(someSpan, Role.MENU_ITEM);
<a name="line58"></a>
<a name="line59"></a>  assertEquals(&#39;someDiv\&#39;s role should be MENU&#39;,
<a name="line60"></a>      Role.MENU, ARIA.getRole(someDiv));
<a name="line61"></a>  assertEquals(&#39;someSpan\&#39;s role should be MENU_ITEM&#39;,
<a name="line62"></a>      Role.MENU_ITEM, ARIA.getRole(someSpan));
<a name="line63"></a>
<a name="line64"></a>  var div = goog.dom.createElement(goog.dom.TagName.DIV);
<a name="line65"></a>  goog.dom.appendChild(sandbox, div);
<a name="line66"></a>  goog.dom.appendChild(div, goog.dom.createDom(goog.dom.TagName.SPAN,
<a name="line67"></a>      {id: &#39;anotherSpan&#39;, role: Role.CHECKBOX}));
<a name="line68"></a>  assertEquals(&#39;anotherSpan\&#39;s role should be CHECKBOX&#39;,
<a name="line69"></a>      Role.CHECKBOX, ARIA.getRole(goog.dom.getElement(&#39;anotherSpan&#39;)));
<a name="line70"></a>}
<a name="line71"></a>
<a name="line72"></a>function testGetSetState() {
<a name="line73"></a>  assertThrows(&#39;Should throw because no state is specified.&#39;,
<a name="line74"></a>      function() {
<a name="line75"></a>        ARIA.getState(someDiv);
<a name="line76"></a>      });
<a name="line77"></a>  assertThrows(&#39;Should throw because no state is specified.&#39;,
<a name="line78"></a>      function() {
<a name="line79"></a>        ARIA.getState(someDiv);
<a name="line80"></a>      });
<a name="line81"></a>  ARIA.setState(someDiv, State.LABELLEDBY, &#39;someSpan&#39;);
<a name="line82"></a>
<a name="line83"></a>  assertEquals(&#39;someDiv\&#39;s labelledby state should be &quot;someSpan&quot;&#39;,
<a name="line84"></a>      &#39;someSpan&#39;, ARIA.getState(someDiv, State.LABELLEDBY));
<a name="line85"></a>
<a name="line86"></a>  // Test setting for aria-activedescendant with empty value.
<a name="line87"></a>  assertFalse(someDiv.hasAttribute ?
<a name="line88"></a>      someDiv.hasAttribute(&#39;aria-activedescendant&#39;) :
<a name="line89"></a>      !!someDiv.getAttribute(&#39;aria-activedescendant&#39;));
<a name="line90"></a>  ARIA.setState(someDiv, State.ACTIVEDESCENDANT, &#39;someSpan&#39;);
<a name="line91"></a>  assertEquals(&#39;someSpan&#39;, ARIA.getState(someDiv, State.ACTIVEDESCENDANT));
<a name="line92"></a>  ARIA.setState(someDiv, State.ACTIVEDESCENDANT, &#39;&#39;);
<a name="line93"></a>  assertFalse(someDiv.hasAttribute ?
<a name="line94"></a>      someDiv.hasAttribute(&#39;aria-activedescendant&#39;) :
<a name="line95"></a>      !!someDiv.getAttribute(&#39;aria-activedescendant&#39;));
<a name="line96"></a>
<a name="line97"></a>  // Test setting state that has a default value to empty value.
<a name="line98"></a>  assertFalse(someDiv.hasAttribute ?
<a name="line99"></a>      someDiv.hasAttribute(&#39;aria-relevant&#39;) :
<a name="line100"></a>      !!someDiv.getAttribute(&#39;aria-relevant&#39;));
<a name="line101"></a>  ARIA.setState(someDiv, State.RELEVANT, ARIA.RelevantValues.TEXT);
<a name="line102"></a>  assertEquals(
<a name="line103"></a>      ARIA.RelevantValues.TEXT, ARIA.getState(someDiv, State.RELEVANT));
<a name="line104"></a>  ARIA.setState(someDiv, State.RELEVANT, &#39;&#39;);
<a name="line105"></a>  assertEquals(
<a name="line106"></a>      ARIA.RelevantValues.ADDITIONS + &#39; &#39; + ARIA.RelevantValues.TEXT,
<a name="line107"></a>      ARIA.getState(someDiv, State.RELEVANT));
<a name="line108"></a>}
<a name="line109"></a>
<a name="line110"></a>function testGetStateString() {
<a name="line111"></a>  ARIA.setState(someDiv, State.LABEL, &#39;test_label&#39;);
<a name="line112"></a>  ARIA.setState(
<a name="line113"></a>      someSpan, State.LABEL, ARIA.getStateString(someDiv, State.LABEL));
<a name="line114"></a>  assertEquals(ARIA.getState(someDiv, State.LABEL),
<a name="line115"></a>      ARIA.getState(someSpan, State.LABEL));
<a name="line116"></a>  assertEquals(&#39;The someDiv\&#39;s enum value should be &quot;test_label&quot;.&#39;,
<a name="line117"></a>      &#39;test_label&#39;, ARIA.getState(someDiv, State.LABEL));
<a name="line118"></a>  assertEquals(&#39;The someSpan\&#39;s enum value should be &quot;copy move&quot;.&#39;,
<a name="line119"></a>      &#39;test_label&#39;, ARIA.getStateString(someSpan, State.LABEL));
<a name="line120"></a>  ARIA.setState(someDiv, State.MULTILINE, true);
<a name="line121"></a>  var thrown = false;
<a name="line122"></a>  try {
<a name="line123"></a>    ARIA.getStateString(someDiv, State.MULTILINE);
<a name="line124"></a>  } catch (e) {
<a name="line125"></a>    thrown = true;
<a name="line126"></a>  }
<a name="line127"></a>  assertTrue(&#39;invalid use of getStateString on boolean.&#39;, thrown);
<a name="line128"></a>  ARIA.setState(someDiv, State.LIVE, ARIA.LivePriority.ASSERTIVE);
<a name="line129"></a>  thrown = false;
<a name="line130"></a>  ARIA.setState(someDiv, State.LEVEL, 1);
<a name="line131"></a>  try {
<a name="line132"></a>    ARIA.getStateString(someDiv, State.LEVEL);
<a name="line133"></a>  } catch (e) {
<a name="line134"></a>    thrown = true;
<a name="line135"></a>  }
<a name="line136"></a>  assertTrue(&#39;invalid use of getStateString on numbers.&#39;, thrown);
<a name="line137"></a>}
<a name="line138"></a>
<a name="line139"></a>
<a name="line140"></a>function testGetStateStringArray() {
<a name="line141"></a>  ARIA.setState(someDiv, State.LABELLEDBY, [&#39;1&#39;, &#39;2&#39;]);
<a name="line142"></a>  ARIA.setState(someSpan, State.LABELLEDBY,
<a name="line143"></a>      ARIA.getStringArrayStateInternalUtil(someDiv, State.LABELLEDBY));
<a name="line144"></a>  assertEquals(ARIA.getState(someDiv, State.LABELLEDBY),
<a name="line145"></a>      ARIA.getState(someSpan, State.LABELLEDBY));
<a name="line146"></a>
<a name="line147"></a>  assertEquals(&#39;The someDiv\&#39;s enum value should be &quot;1 2&quot;.&#39;, &#39;1 2&#39;,
<a name="line148"></a>      ARIA.getState(someDiv, State.LABELLEDBY));
<a name="line149"></a>  assertEquals(&#39;The someSpan\&#39;s enum value should be &quot;1 2&quot;.&#39;, &#39;1 2&#39;,
<a name="line150"></a>      ARIA.getState(someSpan, State.LABELLEDBY));
<a name="line151"></a>
<a name="line152"></a>  assertSameElements(&#39;The someDiv\&#39;s enum value should be &quot;1 2&quot;.&#39;,
<a name="line153"></a>      [&#39;1&#39;, &#39;2&#39;],
<a name="line154"></a>      ARIA.getStringArrayStateInternalUtil(someDiv, State.LABELLEDBY));
<a name="line155"></a>  assertSameElements(&#39;The someSpan\&#39;s enum value should be &quot;1 2&quot;.&#39;,
<a name="line156"></a>      [&#39;1&#39;, &#39;2&#39;],
<a name="line157"></a>      ARIA.getStringArrayStateInternalUtil(someSpan, State.LABELLEDBY));
<a name="line158"></a>}
<a name="line159"></a>
<a name="line160"></a>
<a name="line161"></a>function testGetStateNumber() {
<a name="line162"></a>  ARIA.setState(someDiv, State.LEVEL, 1);
<a name="line163"></a>  ARIA.setState(
<a name="line164"></a>      someSpan, State.LEVEL, ARIA.getStateNumber(someDiv, State.LEVEL));
<a name="line165"></a>  assertEquals(ARIA.getState(someDiv, State.LEVEL),
<a name="line166"></a>      ARIA.getState(someSpan, State.LEVEL));
<a name="line167"></a>  assertEquals(&#39;The someDiv\&#39;s enum value should be &quot;1&quot;.&#39;, &#39;1&#39;,
<a name="line168"></a>      ARIA.getState(someDiv, State.LEVEL));
<a name="line169"></a>  assertEquals(&#39;The someSpan\&#39;s enum value should be &quot;1&quot;.&#39;, &#39;1&#39;,
<a name="line170"></a>      ARIA.getState(someSpan, State.LEVEL));
<a name="line171"></a>  assertEquals(&#39;The someDiv\&#39;s enum value should be &quot;1&quot;.&#39;, 1,
<a name="line172"></a>      ARIA.getStateNumber(someDiv, State.LEVEL));
<a name="line173"></a>  assertEquals(&#39;The someSpan\&#39;s enum value should be &quot;1&quot;.&#39;, 1,
<a name="line174"></a>      ARIA.getStateNumber(someSpan, State.LEVEL));
<a name="line175"></a>  ARIA.setState(someDiv, State.MULTILINE, true);
<a name="line176"></a>  var thrown = false;
<a name="line177"></a>  try {
<a name="line178"></a>    ARIA.getStateNumber(someDiv, State.MULTILINE);
<a name="line179"></a>  } catch (e) {
<a name="line180"></a>    thrown = true;
<a name="line181"></a>  }
<a name="line182"></a>  assertTrue(&#39;invalid use of getStateNumber on boolean.&#39;, thrown);
<a name="line183"></a>  ARIA.setState(someDiv, State.LIVE, ARIA.LivePriority.ASSERTIVE);
<a name="line184"></a>  thrown = false;
<a name="line185"></a>  try {
<a name="line186"></a>    ARIA.getStateBoolean(someDiv, State.LIVE);
<a name="line187"></a>  } catch (e) {
<a name="line188"></a>    thrown = true;
<a name="line189"></a>  }
<a name="line190"></a>  assertTrue(&#39;invalid use of getStateNumber on strings.&#39;, thrown);
<a name="line191"></a>}
<a name="line192"></a>
<a name="line193"></a>function testGetStateBoolean() {
<a name="line194"></a>  assertNull(ARIA.getStateBoolean(someDiv, State.MULTILINE));
<a name="line195"></a>
<a name="line196"></a>  ARIA.setState(someDiv, State.MULTILINE, false);
<a name="line197"></a>  assertFalse(ARIA.getStateBoolean(someDiv, State.MULTILINE));
<a name="line198"></a>
<a name="line199"></a>  ARIA.setState(someDiv, State.MULTILINE, true);
<a name="line200"></a>  ARIA.setState(someSpan, State.MULTILINE,
<a name="line201"></a>      ARIA.getStateBoolean(someDiv, State.MULTILINE));
<a name="line202"></a>  assertEquals(ARIA.getState(someDiv, State.MULTILINE),
<a name="line203"></a>      ARIA.getState(someSpan, State.MULTILINE));
<a name="line204"></a>  assertEquals(&#39;The someDiv\&#39;s enum value should be &quot;true&quot;.&#39;, &#39;true&#39;,
<a name="line205"></a>      ARIA.getState(someDiv, State.MULTILINE));
<a name="line206"></a>  assertEquals(&#39;The someSpan\&#39;s enum value should be &quot;true&quot;.&#39;, &#39;true&#39;,
<a name="line207"></a>      ARIA.getState(someSpan, State.MULTILINE));
<a name="line208"></a>  assertEquals(&#39;The someDiv\&#39;s enum value should be &quot;true&quot;.&#39;, true,
<a name="line209"></a>      ARIA.getStateBoolean(someDiv, State.MULTILINE));
<a name="line210"></a>  assertEquals(&#39;The someSpan\&#39;s enum value should be &quot;true&quot;.&#39;, true,
<a name="line211"></a>      ARIA.getStateBoolean(someSpan, State.MULTILINE));
<a name="line212"></a>  ARIA.setState(someDiv, State.LEVEL, 1);
<a name="line213"></a>  var thrown = false;
<a name="line214"></a>  try {
<a name="line215"></a>    ARIA.getStateBoolean(someDiv, State.LEVEL);
<a name="line216"></a>  } catch (e) {
<a name="line217"></a>    thrown = true;
<a name="line218"></a>  }
<a name="line219"></a>  assertTrue(&#39;invalid use of getStateBoolean on numbers.&#39;, thrown);
<a name="line220"></a>  ARIA.setState(someDiv, State.LIVE, ARIA.LivePriority.ASSERTIVE);
<a name="line221"></a>  thrown = false;
<a name="line222"></a>  try {
<a name="line223"></a>    ARIA.getStateBoolean(someDiv, State.LIVE);
<a name="line224"></a>  } catch (e) {
<a name="line225"></a>    thrown = true;
<a name="line226"></a>  }
<a name="line227"></a>  assertTrue(&#39;invalid use of getStateBoolean on strings.&#39;, thrown);
<a name="line228"></a>}
<a name="line229"></a>
<a name="line230"></a>function testGetSetActiveDescendant() {
<a name="line231"></a>  ARIA.setActiveDescendant(someDiv, null);
<a name="line232"></a>  assertNull(&#39;someDiv\&#39;s activedescendant should be null&#39;,
<a name="line233"></a>      ARIA.getActiveDescendant(someDiv));
<a name="line234"></a>
<a name="line235"></a>  ARIA.setActiveDescendant(someDiv, someSpan);
<a name="line236"></a>
<a name="line237"></a>  assertEquals(&#39;someDiv\&#39;s active descendant should be &quot;someSpan&quot;&#39;,
<a name="line238"></a>      someSpan, ARIA.getActiveDescendant(someDiv));
<a name="line239"></a>}
<a name="line240"></a>
<a name="line241"></a>function testGetSetLabel() {
<a name="line242"></a>  assertEquals(&#39;someDiv\&#39;s label should be &quot;&quot;&#39;, &#39;&#39;, ARIA.getLabel(someDiv));
<a name="line243"></a>
<a name="line244"></a>  ARIA.setLabel(someDiv, &#39;somelabel&#39;);
<a name="line245"></a>  assertEquals(&#39;someDiv\&#39;s label should be &quot;somelabel&quot;&#39;, &#39;somelabel&#39;,
<a name="line246"></a>      ARIA.getLabel(someDiv));
<a name="line247"></a>}
</pre>


</body>
</html>
